<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Cases extends Model
{
    /**
     * 与模型关联的表名
     *
     * @var string
     */
    protected $table = 'cases';

    /*
     * 多对多  获取该标签的所有文章
     */
    public function articles()
    {
        return $this->belongsToMany('App\Models\Article', 'article_cases', 'case_id', 'article_id');
    }
    //
    public function getCase()
    {
        return $this->orderBy('weight', 'desc')->get();
    }

    public function getCaseId($str)
    {
        $cases = explode(",", $str);
        $case_id = $this->select('id')->whereIn('name', $cases)->get();
        $cases_id = array();
        foreach($case_id as $k=>$v){
            $cases_id[] = $v->id;
        }
        return $cases_id;
    }
}
